package com.peng.edu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.peng.edu.entity.Course;
import com.peng.edu.entity.Teacher;
import com.peng.edu.entity.chapter.ChapterVo;
import com.peng.edu.entity.frontVo.CourseFrontVo;
import com.peng.edu.entity.frontVo.CourseWebVo;
import com.peng.edu.service.ChapterService;
import com.peng.edu.service.CourseService;
import com.peng.edu.service.TeacherService;
import com.peng.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/edu/courseFront")
@CrossOrigin
public class CourseFrontController {
    @Autowired
    private TeacherService teacherService;
    @Autowired
    private CourseService courseService;
    @Autowired
    private ChapterService chapterService;
    //按照条件查询课程信息返回前端页面
    @PostMapping("/getCourseAll/{page}/{limit}")
    public Result getCourseAll(@RequestBody(required = false) CourseFrontVo courseFrontVo,@PathVariable Integer page,@PathVariable Integer limit){
        Page<Course> coursePage = new Page<>(page, limit);
        Map<String, Object> map = courseService.getCourseAll(coursePage ,courseFrontVo);
        return Result.ok().data(map);
    }

    //根据课程id获取课程详细信息
    @GetMapping("/getBaseCourseInfo/{id}")
    public Result getBaseCourseInfo(@PathVariable String id){
        CourseWebVo courseWebVo= courseService.getBaseCourseInfo(id);
        List<ChapterVo> chapterVoList = chapterService.getChapterVideo(id);
        HashMap<String, Object> map = new HashMap<>();
        map.put("courseWebVo",courseWebVo);
        map.put("chapterVoList",chapterVoList);
        return Result.ok().data(map);
    }

    @PostMapping("/getCourseById/{id}")
    public CourseWebVo getCourseById(@PathVariable String id){
        CourseWebVo baseCourseInfo = courseService.getBaseCourseInfo(id);
        return baseCourseInfo;
    }
}
